/**
 * 毕业模版
 */
<template>
  <div class="courseBox">
    <div class="courseBoxTop">
      <div class="courseBoxTopSearch">
        <div class="courseName">
          <span>模板名称：</span>
          <el-input v-model="examPaper" placeholder="请输入考试名称" />
        </div>
        <div class="courseName">
          <span>证书分类：</span>
          <el-select v-model="value" placeholder="请选择">
            <el-option
               v-for="(item, index) in typelist"
              :key="index"
              :label="item.typeName"
              :value="item.typeName"
            >
            </el-option>
          </el-select>
        </div>
        <div class="searchAndReset">
          <el-button @click="search" class="searchBtn">
            <i class="el-icon-search"></i>
            <span>搜索</span>
          </el-button>
          <el-button @click="refreshInput" class="resetBtn" >
            <i class="el-icon-refresh"></i>
            <span>重置</span>
          </el-button>
        </div>
      </div>
    </div>

    <!-- 管理列表 -->
    <div class="courseBoxBottom">
      <div class="bottomHeader">
        <el-button type="primary" @click="addTemplate">添加模版</el-button>
        <el-button type="danger" @click="moreDelete">批量删除</el-button>
      </div>
      <!-- 表格 -->
      <div class="bottomMian">
        <el-table
          ref="multipleTable"
          @select-all="itemHandleSelectionAll"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" align="content"> </el-table-column>
          <el-table-column type="index" label="序号" align="content">
          </el-table-column>
          <el-table-column label="证书名称" prop="certificateName" align="content">
          </el-table-column>
          <el-table-column label="证书背景图" prop="certificateSettingImg" align="content">
           <template slot-scope="scope">
            
            <el-image
              style="width: 50px; height: 50px; margin-bottom:-4px"
              :src="scope.row.certificateSettingImg"
            >
            </el-image>
          </template>
          </el-table-column>
          <el-table-column label="证书分类" prop="certificateType" align="content">
          </el-table-column>
          <el-table-column fixed="right" label="操作" align="content">
            <template slot-scope="scope">
              <i style="color: #339dff" @click="DetaTemplate(scope.$index, scope.row)">详情</i>
            </template>
          </el-table-column>
        </el-table>

      </div>
      <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pageNum"
        :page-sizes="[2, 3, 4, 5]"
        :page-size="query.pageSize"
        prev-text="上一页"
        next-text="下一页"
        layout=" prev, pager, next"
        :total="query.total"
      ></el-pagination>

      <div class="jumper">
        跳到第
        <input type="text" ref="pageNum" :value="query.pageNum" />
        页
      </div>
      <button @click="goPage" style="color:white">确定</button>
    </div>
    </div>
  </div>
</template>

<script>
import "@/styles/picture.scss";
import {
CertificateList,
Certificatedel
} from "@/api/graduation/Graduationtemplate";
import {
  getNationApi
} from "@/api/basics/classroom";
export default {
  data() {
    return {
      examPaper: "",
     query: {
        pageNum: 1,
        pageSize: 6,
        total: 0
      },
      tableData: [],
      examId: "",
      length: "",
      ids: '',
      value: "",
      typelist:'',
      
    };
  },

  mounted() {
    this.getList();
    this.gettreeList()
  },

  methods: {
    async getList(){
      let res=await CertificateList(this.query)
      console.log(res)
      this.tableData=res.rows
      this.query.total = res.total;
    },
    //搜索
    search(){
      let obj={
        certificateName: this.examPaper,
        certificateType: this.value,
        
      }
      CertificateList(obj).then(res => {
        console.log("222", res);
        this.tableData = res.rows;
        
      });
    },
      // 分页
    // 改变每页条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.query.pageSize = val;
       this.getList();
    },
    //切换页数，执行方法
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.query.pageNum = val;
        this.getList();
    },
    goPage() {
      let { value } = this.$refs.pageNum;
      console.log("1", value);
      this.query.pageNum = Number(value);
        this.getList();
    },
    //类型
    async gettreeList(){
     let res=await getNationApi({parentId:209}) 
     console.log('233',res)
     this.typelist=res.rows
     console.log('23',this.typelist)
   },
    // 添加模版
    addTemplate(){
        this.$router.push({
        path: '/Graduation/Addgraduationtemplate',
      });
    },
    //查看
    DetaTemplate(index,row){
      console.log(row)
        this.$router.push({
        path: '/Graduation/detailsgraduation',
        params: {
          id: row.id
        }  
      });
      localStorage.setItem('id',row.id)
    },
     // 重置
    refreshInput() {
      this.examPaper = "";
      this.value = "";
      this.getList();
    },
    // 全选
    itemHandleSelectionAll(selection) {
      console.log(selection.length);
      this.length = selection.length;
    },
   //批量
    handleSelectionChange(val){
      var arrTostring = [];
      val.forEach(item => {
        if (arrTostring.indexOf(item.id) === -1) {
          arrTostring.push(item.id);
        }
      });
      this.ids = arrTostring;
      console.log('333',this.ids)
    },
     //批量删除
    moreDelete() {
      console.log(this.ids);
      this.$confirm("确认删除记录吗?", "提示", {
        type: "warning"
      })
        .then(() => {
          Certificatedel(this.ids).then(res => {
            console.log(res);
            this.getList();
            this.$message.success("删除成功");
          });
        })
        .catch(() => {});
    },
     

  },
};
</script>

<style lang="scss" scoped>
.courseBoxTopSearch {
  ::v-deep .el-input__inner {
    height: 36px;
    line-height: 36px;
  }
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: right;
  margin-top: 20px;
  margin-right: 150px;
  .jumper {
    font-size: 14px;
    margin-left: 20px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    input {
      width: 40px;
      height: 26px;
      margin: 0 5px;
      text-align: center;
      border: solid 1px #e6e6e6;
      border-radius: 5px;
      color: #666;
      outline-style: none;
    }
  }
  button {
    height: 28px;
    line-height: 28px;
    border-radius: 5px;
    background-color: #4895db;
    border: solid 1px #4895db;
    color: #fff;
    font-size: 14px;
    padding: 0 8px;
  }
}
.action {
  cursor: pointer;

  span {
    font-size: 12px;
    color: #4b93d5;
  }
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: right;
  margin-top: 20px;
  margin-right: 150px;
  .jumper {
    font-size: 14px;
    margin-left: 20px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    input {
      width: 40px;
      height: 26px;
      margin: 0 5px;
      text-align: center;
      border: solid 1px #e6e6e6;
      border-radius: 5px;
      color: #666;
      outline-style: none;
    }
  }
  button {
    height: 28px;
    line-height: 28px;
    border-radius: 5px;
    background-color: #4895db;
    border: solid 1px #4895db;
    color: #fff;
    font-size: 14px;
    padding: 0 8px;
  }
}
.alert {
  width: 100%;
  margin-bottom: 10px;
  border: 1px solid #caedff;
  background: #e6f7ff;
}
</style>